#!/bin/bash
#
# Copyright 2015-2017 Adrian DC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# === LegacyXperia Automatic Releaser ===
function autoreleaselegacyxperia()
{
  # Usage: autoreleaselegacyxperia [devices] (Automated LegacyXperia 7x30 releaser)

  # AndroidDev
  cdand;

  # When option enabled, sync repository tree
  if ! shtools-builds-nosync-active && [ -z "${*}" ]; then
    cdlineage;
    reposy;
  fi;

  # Devices to build
  local devices=${*:-anzu haida coconut urushi smultron mango hallon iyokan satsuma zeus phoenix};

  # Access project repository and when option enabled, sync tree
  if ! pathchanged cdlineage lx && ! shtools-builds-nosync-active; then
    reposy;
  fi;

  # Patch project
  if ! lineagelxpatcher; then
    return;
  fi;

  # Force clean option
  shtools-builds-cleandevices-enable;

  # Walk through devices
  for device in ${devices}; do

    # ROM build and release
    romautorelease "${device}" lx;

  done;
}
